home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1857 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  910 b 

  1. Path: news.mel.aone.net.au!OzEmail!usenet
  2. From: tedjones@voyager.co.nz (Oliver Jones)
  3. Newsgroups: comp.lang.c++
  4. Subject: const member functions
  5. Date: Sat, 13 Jan 1996 14:48:39 GMT
  6. Organization: Ted Jones Motor Co Ltd.
  7. Message-ID: <4d8d8f$b30@oznet07.ozemail.com.au>
  8. NNTP-Posting-Host: ts1p04.net.hamilton.voyager.co.nz
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Email reply's please.
  12.  
  13. Could someone please explain to me the significance of the "const" in
  14. this member function declaration.
  15.  
  16. int MyFunc(const char *s) const { 
  17.     ... 
  18. };
  19.  
  20. I became aware of these when my compiler complained I couldn't call a
  21. non-const member function from a pointer to a const parameter class.
  22. eg: I couldn't do this:
  23.  
  24. int MyFunc2(const TMyClass *p) {
  25.     int i = p->MyFunc("hi");
  26. }
  27.  
  28. I needed to add the const to the declaration above.  Care to explain
  29. the significance and "side effects" of the const member as defined
  30. above.
  31.  
  32. Thanks.
  33.  
  34.